package com.usian.user.listener;

import com.rabbitmq.client.Channel;
import com.usian.model.user.dtos.AuthDto;
import com.usian.user.config.RabbitmqConfig;
import com.usian.user.service.ApUserRealnameService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class  UserRealnameListener {

    @Autowired
    private ApUserRealnameService apUserRealnameService;


    @RabbitListener(queues = {RabbitmqConfig.QUEUE_AUTHAUTO_USER})
    public void toAutoUpdateStatus(String msg, Channel channel, Message message) throws IOException {
        // 监听Id
        try {
            AuthDto authDto = new AuthDto();
            authDto.setId(Integer.valueOf(msg));
            apUserRealnameService.autoUpdateStatus(authDto);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        }catch (Exception e) {
            e.printStackTrace();//
            //丢弃这条消息
            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
        }

    }
}
